package com.zmovie.common.response;

import lombok.Data;

/**
 * @author 挚爱之夕
 * @version 1.0
 * @implSpec 控制层统一返回对象
 * @since 2023 - 07 - 19 - 12:08
 */
@Data
public class CommonReturnType {
    //表明对应请求的返回处理结果"success"或"fail"
    private String status;
    //若status=success,,则data内返回前端需要的json数据
    //若status-=fail,则data内使用通用的错误码格式
    private Object data;
    public static final String SUCCESS = "success";
    public static final String FAIL = "fail";
    public static CommonReturnType success(Object result){
        return create(result,SUCCESS);
    }
    public static CommonReturnType fail(Object result){
        return create(result, FAIL);
    }
    public static CommonReturnType create(Object result, String status){
        CommonReturnType commonReturnType = new CommonReturnType();
        commonReturnType.setData(result);
        commonReturnType.setStatus(status);
        return commonReturnType;
    }
}
